package com.ants.boot.system.service.impl;

import com.ants.boot.system.dao.SysRoleMenuMapper;
import com.ants.boot.system.domain.SysRoleMenu;
import com.ants.boot.system.service.SysRoleMenuService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 蚂蚁会花呗
 * @date 2022/3/15 16:42
 */
@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {


    @Override
    public List<SysRoleMenu> listSysRoleMenuByRoleId(Integer roleId) {
        QueryWrapper<SysRoleMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(SysRoleMenu::getRoleId,roleId);
        return this.list(queryWrapper);
    }

    @Override
    public List<Integer> listMenuIdsByRoleId(Integer roleId) {
        List<Integer> menuIds = new ArrayList<>();
        List<SysRoleMenu> list = listSysRoleMenuByRoleId(roleId);
        if (!list.isEmpty()){
            menuIds = list.stream().map(SysRoleMenu::getMenuId).collect(Collectors.toList());
        }
        return menuIds;
    }

    @Override
    public boolean deleteMenuIdsByRoleId(Integer roleId) {
        QueryWrapper<SysRoleMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(SysRoleMenu::getRoleId,roleId);
        return this.remove(queryWrapper);
    }

    @Override
    public boolean saveBatchRoleMenu(List<SysRoleMenu> list) {
        return this.saveBatch(list);
    }
}
